//
// Created by liuzhen on 7/26/18.
//
#include "firstNode.h"

MTypeId     firstNode::id( 0x80005 );
MObject     firstNode::input;
MObject     firstNode::output;

firstNode::firstNode() {

}

firstNode::~firstNode() {


}


MStatus firstNode ::compute(const MPlug &plug, MDataBlock &data) {
    MStatus status;
    if (plug == output){
        MDataHandle inputHandle = data.inputValue( input );
        double result = inputHandle.asDouble();

        MDataHandle outputHandle =  data.outputValue( output );
        outputHandle.set(result);
        outputHandle.setClean();
    }

    else{
        return MS::kUnknownParameter;
    }

    return MS::kSuccess;

}

MStatus firstNode::initialize() {
    MStatus status;
    MFnNumericAttribute nAttr;


    input = nAttr.create("input", "in", MFnNumericData::kDouble);
    nAttr.setKeyable( true );
    nAttr.setStorable( true );

    output = nAttr.create("output", "out", MFnNumericData::kDouble);
    nAttr.setWritable( false );

    addAttribute( input );
    addAttribute( output );


    attributeAffects(input, output);

    return MS::kSuccess;

}
void* firstNode ::creator() {
    return new firstNode();
}